﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using FancyBattles.GameEntities;

namespace FancyBattles.GameScreen.StateMachine
{
    class DefinePowerState : State
    {
        public const float MAXIMUM_SPEED = 5.0f;
        public const float MINIMUM_SPEED = 1.0f;

        private float power = 1.0f;
        private float powerDirection = 0.062f;

        private BouncingBitch selectedBitch;

        public static Animation arrowsBlue;
        public static Animation arrowsRed;
        public static AnimationPowerArrow arrowAnimation;

        public DefinePowerState(GameplayScreen parentScreen, PlayerIndex player)
            : base(parentScreen, player)
        {
            selectedBitch = (from bitch in BouncingBitch.BitchesList where bitch.IsSelected == true && bitch.Player.Equals(player) select bitch).First();
            arrowAnimation.rotationAngle = selectedBitch.directionArrowAngle;
            if(player.Equals(PlayerIndex.One))
            {
                arrowAnimation.FrameIndex = 0;
                arrowAnimation.PlayAnimation(arrowsBlue);
            }
            else
            {
                arrowAnimation.FrameIndex = 0;
                arrowAnimation.PlayAnimation(arrowsRed);
            }
        }

        public override void Update(GameTime gameTime)
        {
            //arrowAnimation.PlayAnimation(arrowsBlue);
            if (power > MAXIMUM_SPEED)
            {
                power = MINIMUM_SPEED;
            }
            power += powerDirection;

            if (InputHandler.isConfirm(player))
            {
                selectedBitch = (from bitch in BouncingBitch.BitchesList where bitch.IsSelected == true && bitch.Player.Equals(player) select bitch).First();
                selectedBitch.Speed *= power * 5;
                selectedBitch.IsConfirmed = true;
                selectedBitch.ChangeTexture(BouncingBitch.animationState.Confirmed);

                //change variables to keep texture drawn
                selectedBitch.arrowDirectionFrame = arrowAnimation.FrameIndex;

                ParentScreen.ScreenStates[player] = new SelectState(ParentScreen, player);
            }
            if (InputHandler.isCancel(player))
            {
                ParentScreen.ScreenStates[player] = new DefineMoveState(ParentScreen, player);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            arrowAnimation.Draw(gameTime, ParentScreen.ScreenManager.SpriteBatch, new Vector2(selectedBitch.Position.X + 15, selectedBitch.Position.Y + 15), Microsoft.Xna.Framework.Graphics.SpriteEffects.None);
            //ParentScreen.ScreenManager.SpriteBatch.DrawString(ParentScreen.ScreenManager.Font, "Estado de power: " + power, new Vector2(300, 300), Color.Red);
        }
    }
}
